#!/usr/bin/python
from pprint import pprint
import xmlrpclib
import sys
from torrent import torrentfile

class bmanager:

    def __init__(self, serverurl, login, password, verbose=0):
        self.svr = xmlrpclib.ServerProxy(uri=serverurl, verbose=verbose)

        try:
            self.session_id = self.svr.bmanager.login(login, password)
        except xmlrpclib.Error, v:
            print "ERROR:", v
            sys.exit()

    def logout(self):
        return self.svr.bmanager.logout(self.session_id)

    def get_users(self):
        return self.svr.bmanager.get_users(self.session_id)

    def get_my_filesets(self):
        return self.svr.bmanager.get_my_filesets(self.session_id)

    def get_my_subscribed_filesets(self):
        return self.svr.bmanager.get_my_subscribed_filesets(self.session_id)

    def publish_file(self, fileset, torrent):        
        print "publishing file ", torrent.name()

        print "th", torrent.hash(), " fs", fileset, " size ", torrent.size()
        return self.svr.bmanager.publish_file(self.session_id, torrent.hash(), fileset, torrent.size(), torrent.bin())
        
